package com.health.viewscontrols.settings;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.ContactsContract;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.health.R;
import com.health.adapter.UPDataMenuGridAdapter;
import com.health.adapter.UpDataMenuGridAdapter2;
import com.health.db.FDbManager;
import com.health.model.UpDataReturn;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tools.DownLoadTools;
import com.health.tools.GetPost;
import com.health.tools.GetPostJTYS;
import com.health.tools.GlobalConts;
import com.health.tools.GlobalContsJTYS;
import com.health.tools.JX_FWXMB;
import com.health.tools.ResultTextDialog;
import com.health.tools.SPUtil;
import com.health.tools.WebService;
import com.health.viewscontrols.HomeDataDownloadActivity;
import com.health.viewscontrols.NovaActivity;
import com.health.viewscontrols.NovaApplication;
import com.health.viewscontrols.NovaPtActivity;
import com.health.webservices.WebServiceConts;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 同步数据
 */
public class DataSynchronizationMainActivity extends NovaPtActivity implements OnClickListener {
    private static final int MAX_PROGRESS = 100;
    private static final int PRO = 10;
    private int progress = 0;
    private ProgressDialog mProgressDialog;
    private ResultTextDialog resultDialog;
    private GridView gd_menu;
    private TextView title;
    private ImageView img_photo;
    private TextView tv_name;
    private UpDataMenuGridAdapter2 menuAdapter;
    private Button btn_back;
    private Button btn_up;
    private String str_xzq = "";
    private FDbManager fdbmanger = null;
    List<ARCHIVE_BASEINFO> isUpdate = new ArrayList<>();
    private int sumSize;
    private int successCount;
    private int failCount;
    private static final int DOWNLOAD_OVER = 1;
    private static final int NO_DATA = 3;
    private static final int SHOW_UPLOAD_RESULT = 4;
    private static final int UPLOAD_FUMYD2 = 5;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // StrictMode.ThreadPolicy policy=new
        // StrictMode.ThreadPolicy.Builder().permitAll().build();
        // StrictMode.setThreadPolicy(policy);
        setContentView(R.layout.jkjy_main_content);
        findViews();
        setListeners();

    }

    @Override
    public void findViews() {
        gd_menu = (GridView) findViewById(R.id.gd_menu);
        title = (TextView) findViewById(R.id.title);
        title.setText("数据下载");

        img_photo = (ImageView) findViewById(R.id.img_photo);
        img_photo.setImageResource(R.drawable.settings_data);
        tv_name = (TextView) findViewById(R.id.tv_name);
        try {
            findViewById(R.id.bt_history).setVisibility(View.GONE);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            findViewById(R.id.bt_save).setVisibility(View.GONE);
        } catch (Exception e) {
            e.printStackTrace();
        }
        TextView tv_title = (TextView)findViewById(R.id.tv_title);
        LinearLayout ll_finish = (LinearLayout)findViewById(R.id.ll_finish);
        tv_name.setText("数据下载");
        tv_title.setText("数据下载");
        menuAdapter = new UpDataMenuGridAdapter2(this, GlobalContsJTYS.MENU_SYNCHRONIZATION);
        gd_menu.setAdapter(menuAdapter);
        btn_back = (Button) findViewById(R.id.btn_back);
        btn_up = (Button) findViewById(R.id.btn_up);
        btn_up.setVisibility(View.GONE);

        str_xzq = SPUtil.getstr_xzq(DataSynchronizationMainActivity.this);
        fdbmanger = NovaApplication.fdbmanger;
        if (resultDialog == null) {
            resultDialog = new ResultTextDialog(DataSynchronizationMainActivity.this);
        }
        ll_finish.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    /**
     * 更新机构人员
     */
    public void updateJGRY() {
        String fileURl = GlobalConts.getUrlPost() + GetPost.URL_DBSYNC + "?orgDistrictId=" + str_xzq;
        DownLoadTools downLoad = new DownLoadTools(DataSynchronizationMainActivity.this);
        downLoad.downloadFile(fileURl, NovaApplication.dbPath);
    }

    @Override
    public void setListeners() {
        btn_back.setOnClickListener(this);
        // 菜单选项
        gd_menu.setOnItemClickListener(new OnItemClickListener() {

            @SuppressLint("HandlerLeak")
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (!GlobalConts.isNetworkAvailable(DataSynchronizationMainActivity.this)) {
                    showTextDialog("请先检查网络");
                    return;
                }
                if (checkToken()) {
                    showTextDialog("试用状态下无法进行数据下载!");
                    return;
                }

                if (position == 0) {

                    Intent intent = new Intent(DataSynchronizationMainActivity.this, HomeDataDownloadActivity.class);
                    intent.putExtra("setting", "setting");
                    startActivity(intent);
                } else if (position == 1) {
                    getSynUsersData();
                } else if (position == 2) {
                    if (resultDialog == null) {
                        resultDialog = new ResultTextDialog(DataSynchronizationMainActivity.this);
                    }
                    resultDialog.show("数据正在下载中，请稍候...");
					downloadFWXMB();
                }else if (position == 3){
//                    downloadGXY();
                    downloadDrugs();
                }else if (position == 4){
                    downloadTNB();
                }

            }
        });

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_back:
                finish();
                break;

            default:
                break;
        }

    }

    private void initProgressDialog() {
        mProgressDialog = new ProgressDialog(DataSynchronizationMainActivity.this);
        // progressDialog.setIcon(R.drawable.ic_launcher);
        mProgressDialog.setTitle("正在同步数据");
        mProgressDialog.setMessage("请稍候...");
        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);// 璁剧疆杩涘害鏉″璇濇//鏍峰紡锛堟按骞筹紝鏃嬭浆锛�

    }

    /**
     * 获取用户数据
     */
    private void getSynUsersData() {
        try {
            if (GlobalConts.isNetworkAvailable(DataSynchronizationMainActivity.this)) {
                new AlertDialog.Builder(DataSynchronizationMainActivity.this).setTitle("提示")
                        .setMessage("是否要同步本机构用户？")
                        .setPositiveButton("是", new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                initProgressDialog();
                                sumSize = 0;
                                successCount = 0;
                                showProgressDialog("正在获取数据...");
                                @SuppressLint("HandlerLeak")
                                Handler handler = new Handler() {
                                    @Override
                                    public void handleMessage(Message msg) {
                                        super.handleMessage(msg);
                                        System.out.println("webservice");
                                        try {
                                            new WebService(mContext) {
                                                @Override
                                                public void start(String message) {
                                                    super.start(message);
                                                    System.out.println("test111" + message);

                                                }

                                                @Override
                                                public void onSynchronize(String message, int syncCount,
                                                                          int dataSize) {
                                                    super.onSynchronize(message, syncCount, dataSize);
                                                    sumSize = dataSize;
                                                    successCount = syncCount;
                                                    cancelProgressDialog();
                                                    runOnUiThread(new Runnable() {
                                                        @Override
                                                        public void run() {
                                                            if (mProgressDialog != null
                                                                    && !mProgressDialog.isShowing()) {
                                                                mProgressDialog.show();
                                                            }
                                                        }
                                                    });
                                                    mProgressDialog.setMax(dataSize);
                                                    mProgressDialog.setProgress(syncCount);
                                                }

                                                @Override
                                                public void complete(String message) {
                                                    super.complete(message);
                                                    cancelProgressDialog();
                                                    if (mProgressDialog != null) {
                                                        mProgressDialog.dismiss();
                                                        mProgressDialog.cancel();
                                                    }
                                                    runOnUiThread(new Runnable() {

                                                        @Override
                                                        public void run() {
                                                            resultDialog.setText("下载数据总共" + sumSize
                                                                    + "条,保存成功" + successCount + "条,保存失败"
                                                                    + (sumSize - successCount) + "条");
                                                            resultDialog.showCancleLong();
                                                        }
                                                    });
                                                }

                                                @Override
                                                public void onError(String message) {
                                                    System.out.println("同步本机构人员失败");
                                                    cancelProgressDialog();
                                                    if (mProgressDialog != null) {
                                                        mProgressDialog.dismiss();
                                                        mProgressDialog.cancel();
                                                    }
                                                    runOnUiThread(new Runnable() {

                                                        @Override
                                                        public void run() {
                                                            resultDialog.setText("下载数据总共" + sumSize
                                                                    + "条,保存成功" + successCount + "条,保存失败"
                                                                    + (sumSize - successCount) + "条");
                                                            resultDialog.showCancleLong();

                                                        }
                                                    });

                                                }

                                                ;
                                            }.synchrodata(SPUtil.getStr_jdrno(DataSynchronizationMainActivity.this));
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                            if (mProgressDialog != null) {
                                                mProgressDialog.dismiss();
                                                mProgressDialog.cancel();
                                            }
                                            runOnUiThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                    resultDialog.setText("数据同步失败");
                                                    resultDialog.showCancleLong();
                                                }
                                            });
                                        }
                                    }
                                };
                                handler.sendMessage(new Message());
                            }

                        }).setNegativeButton("否", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }

                }).show();
                //
            } else {
                Toast.makeText(DataSynchronizationMainActivity.this, "数据同步失败", Toast.LENGTH_SHORT).show();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 服务项目包下载
     */
    private void downloadFWXMB() {
        try {
            WebService webService = new WebService(mContext) {
                @Override
                public void start(String message) {
                    super.start(message);// 开始 46fas
                    System.out.println("start::" + message);
                    Log.e("start-------", message);
                }

                @Override
                public void complete(String message) {
                    super.complete(message);
                    System.out.println("complete::" + message);
                    cleanData();
                    if (!TextUtils.isEmpty(message)) {
                        UpDataReturn up = JX_FWXMB.jxFwxmbData(message.toString());

                        if (up != null) {
                            if (up.getSize() > 0) {
                                sumSize = up.getSize();
                                successCount = up.getSuccessCount();
                                failCount = up.getFailCount();
                            } else {
                                cleanData();
                            }
                        } else {
                            cleanData();
                        }
                    }
                    mHandler.sendEmptyMessage(DOWNLOAD_OVER);

                }

                @Override
                public void onError(String message) {
                    Log.e("tag", message);
                    mHandler.sendEmptyMessage(DOWNLOAD_OVER);
                }
            };
            HashMap<String, Object> params = new HashMap<String, Object>();
            // params.put("type", "1");
            params.put("organcode", NovaApplication.getJgbh());

            webService.downloaddata(GlobalConts.getUrlPost() + WebServiceConts.WEBSERVICE_URL_FWXMB,
                    WebServiceConts.WEBSERVICE_URL_FWXMB_METHODNAME,
                    WebServiceConts.WEBSERVICE_URL_XZQ_NAMESPACE, null, params, "listdoctorPad");

        } catch (Exception e) {
            mHandler.sendEmptyMessage(DOWNLOAD_OVER);
        }
    }

    /**
     * 检查Token是否存在
     */
    private boolean checkToken() {
        boolean flag = true;
        if (!SPUtil.getIsShiYong(mContext)) {
            //不是试用状态
            flag = false;
        }
        return flag;
    }

    private void cleanData() {
        sumSize = 0;
        successCount = 0;
        failCount = 0;


    }

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {// 此方法在ui线程运行
            switch (msg.what) {
                case DOWNLOAD_OVER:
                    if (resultDialog == null) {
                        resultDialog = new ResultTextDialog(DataSynchronizationMainActivity.this);
                    }
                    resultDialog.setText("下载数据总共" + sumSize + "条,保存成功" + successCount + "条,保存失败" + failCount + "条。");
                    resultDialog.showCancleLong();
                    break;

            }
        }

    };

    /**
     * 高血压数据下载（根据创建人）
     */
    private void downloadGXY() {
        if (GlobalConts.isNetworkAvailable(DataSynchronizationMainActivity.this)) {
            initProgressDialog();
            sumSize = 0;
            successCount = 0;
            showProgressDialog("正在获取数据...");
            @SuppressLint("HandlerLeak")
            Handler handler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    System.out.println("webservice");
                    try {
                        new WebService(mContext) {
                            @Override
                            public void start(String message) {
                                super.start(message);
                                System.out.println("test111" + message);
                            }

                            @Override
                            public void onSynchronize(String message, int syncCount,
                                                      int dataSize) {
                                super.onSynchronize(message, syncCount, dataSize);
                                sumSize = dataSize;
                                successCount = syncCount;
                                cancelProgressDialog();
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        if (mProgressDialog != null
                                                && !mProgressDialog.isShowing()) {
                                            mProgressDialog.show();
                                        }
                                    }
                                });
                                mProgressDialog.setMax(dataSize);
                                mProgressDialog.setProgress(syncCount);
                            }

                            @Override
                            public void complete(String message) {
                                super.complete(message);
                                cancelProgressDialog();
                                if (mProgressDialog != null) {
                                    mProgressDialog.dismiss();
                                    mProgressDialog.cancel();
                                }
                                runOnUiThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        if(successCount>100){
                                            resultDialog.setText("下载数据总共" + sumSize
                                                    + "条,保存成功" + (successCount-1) + "条,保存失败"
                                                    + (sumSize - successCount+1) + "条");
                                        }else if(sumSize==0){
                                            resultDialog.setText("下载数据总共" + 0
                                                    + "条,保存成功" + 0 + "条,保存失败"
                                                    + 0 + "条");
                                        }else{
                                            resultDialog.setText("下载数据总共" + sumSize
                                                    + "条,保存成功" + successCount + "条,保存失败"
                                                    + (sumSize - successCount) + "条");
                                        }

                                        resultDialog.showCancleLong();
                                    }
                                });
                            }

                            @Override
                            public void onError(String message) {
                                System.out.println("下载高血压随访数据失败");
                                cancelProgressDialog();
                                if (mProgressDialog != null) {
                                    mProgressDialog.dismiss();
                                    mProgressDialog.cancel();
                                }
                                runOnUiThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        if(successCount>100){
                                            resultDialog.setText("下载数据总共" + sumSize
                                                    + "条,保存成功" + (successCount-1) + "条,保存失败"
                                                    + (sumSize - successCount+1) + "条");
                                        }else if(sumSize==0){
                                            resultDialog.setText("下载数据总共" + 0
                                                    + "条,保存成功" + 0 + "条,保存失败"
                                                    + 0 + "条");
                                        }else{
                                            resultDialog.setText("下载数据总共" + sumSize
                                                    + "条,保存成功" + successCount + "条,保存失败"
                                                    + (sumSize - successCount) + "条");
                                        }
                                        resultDialog.showCancleLong();

                                    }
                                });

                            }
                        }.synchroGXYOrTNBdata(SPUtil.getStr_jdrno(DataSynchronizationMainActivity.this),"getHyperByUserid");
                    } catch (Exception e) {
                        e.printStackTrace();
                        if (mProgressDialog != null) {
                            mProgressDialog.dismiss();
                            mProgressDialog.cancel();
                        }
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                resultDialog.setText("数据同步失败");
                                resultDialog.showCancleLong();
                            }
                        });
                    }
                }
            };
            handler.sendMessage(new Message());
        } else {
            Toast.makeText(DataSynchronizationMainActivity.this, "下载高血压随访数据失败", Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * 糖尿病数据下载（根据创建人）
     */
    private void downloadTNB() {
        if (GlobalConts.isNetworkAvailable(DataSynchronizationMainActivity.this)) {
            initProgressDialog();
            sumSize = 0;
            successCount = 0;
            showProgressDialog("正在获取数据...");
            @SuppressLint("HandlerLeak")
            Handler handler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    System.out.println("webservice");
                    try {
                        new WebService(mContext) {
                            @Override
                            public void start(String message) {
                                super.start(message);
                                System.out.println("test111" + message);
                            }

                            @Override
                            public void onSynchronize(String message, int syncCount,
                                                      int dataSize) {
                                super.onSynchronize(message, syncCount, dataSize);
                                sumSize = dataSize;
                                successCount = syncCount;
                                cancelProgressDialog();
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        if (mProgressDialog != null
                                                && !mProgressDialog.isShowing()) {
                                            mProgressDialog.show();
                                        }
                                    }
                                });
                                mProgressDialog.setMax(dataSize);
                                mProgressDialog.setProgress(syncCount);
                            }

                            @Override
                            public void complete(String message) {
                                super.complete(message);
                                cancelProgressDialog();
                                if (mProgressDialog != null) {
                                    mProgressDialog.dismiss();
                                    mProgressDialog.cancel();
                                }
                                runOnUiThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        if(successCount>100){
                                            resultDialog.setText("下载数据总共" + sumSize
                                                    + "条,保存成功" + (successCount-1) + "条,保存失败"
                                                    + (sumSize - successCount+1) + "条");
                                        }else if(sumSize==0){
                                            resultDialog.setText("下载数据总共" + 0
                                                    + "条,保存成功" + 0 + "条,保存失败"
                                                    + 0 + "条");
                                        }else{
                                            resultDialog.setText("下载数据总共" + sumSize
                                                    + "条,保存成功" + successCount + "条,保存失败"
                                                    + (sumSize - successCount) + "条");
                                        }
                                        resultDialog.showCancleLong();
                                    }
                                });
                            }

                            @Override
                            public void onError(String message) {
                                System.out.println("下载糖尿病随访数据失败");
                                cancelProgressDialog();
                                if (mProgressDialog != null) {
                                    mProgressDialog.dismiss();
                                    mProgressDialog.cancel();
                                }
                                runOnUiThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        if(successCount>100){
                                            resultDialog.setText("下载数据总共" + sumSize
                                                    + "条,保存成功" + (successCount-1) + "条,保存失败"
                                                    + (sumSize - successCount+1) + "条");
                                        }else if(sumSize==0){
                                            resultDialog.setText("下载数据总共" + 0
                                                    + "条,保存成功" + 0 + "条,保存失败"
                                                    + 0 + "条");
                                        }else{
                                            resultDialog.setText("下载数据总共" + sumSize
                                                    + "条,保存成功" + successCount + "条,保存失败"
                                                    + (sumSize - successCount) + "条");
                                        }
                                        resultDialog.showCancleLong();

                                    }
                                });

                            }
                        }.synchroGXYOrTNBdata(SPUtil.getStr_jdrno(DataSynchronizationMainActivity.this),"getGlyByUserid");
                    } catch (Exception e) {
                        e.printStackTrace();
                        if (mProgressDialog != null) {
                            mProgressDialog.dismiss();
                            mProgressDialog.cancel();
                        }
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                resultDialog.setText("数据同步失败");
                                resultDialog.showCancleLong();
                            }
                        });
                    }
                }
            };
            handler.sendMessage(new Message());
        } else {
            Toast.makeText(DataSynchronizationMainActivity.this, "下载糖尿病随访数据失败", Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * 药品库下载
     */
    private void downloadDrugs() {
        if (GlobalConts.isNetworkAvailable(DataSynchronizationMainActivity.this)) {
            initProgressDialog();
            sumSize = 0;
            successCount = 0;
            showProgressDialog("正在获取数据...");
            @SuppressLint("HandlerLeak")
            Handler handler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    System.out.println("webservice");
                    try {
                        new WebService(mContext) {
                            @Override
                            public void start(String message) {
                                super.start(message);
                                System.out.println("test111" + message);
                            }

                            @Override
                            public void onSynchronize(String message, int syncCount,
                                                      int dataSize) {
                                super.onSynchronize(message, syncCount, dataSize);
                                sumSize = dataSize;
                                successCount = syncCount;
                                cancelProgressDialog();
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        if (mProgressDialog != null
                                                && !mProgressDialog.isShowing()) {
                                            mProgressDialog.show();
                                        }
                                    }
                                });
                                mProgressDialog.setMax(dataSize);
                                mProgressDialog.setProgress(syncCount);
                            }

                            @Override
                            public void complete(String message) {
                                super.complete(message);
                                cancelProgressDialog();
                                if (mProgressDialog != null) {
                                    mProgressDialog.dismiss();
                                    mProgressDialog.cancel();
                                }
                                runOnUiThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        if(successCount>100){
                                            resultDialog.setText("下载数据总共" + sumSize
                                                    + "条,保存成功" + (successCount-1) + "条,保存失败"
                                                    + (sumSize - successCount+1) + "条");
                                        }else if(sumSize==0){
                                            resultDialog.setText("下载数据总共" + 0
                                                    + "条,保存成功" + 0 + "条,保存失败"
                                                    + 0 + "条");
                                        }else{
                                            resultDialog.setText("下载数据总共" + sumSize
                                                    + "条,保存成功" + successCount + "条,保存失败"
                                                    + (sumSize - successCount) + "条");
                                        }

                                        resultDialog.showCancleLong();
                                    }
                                });
                            }

                            @Override
                            public void onError(String message) {
                                System.out.println("下载药品库数据失败");
                                cancelProgressDialog();
                                if (mProgressDialog != null) {
                                    mProgressDialog.dismiss();
                                    mProgressDialog.cancel();
                                }
                                runOnUiThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        if(successCount>100){
                                            resultDialog.setText("下载数据总共" + sumSize
                                                    + "条,保存成功" + (successCount-1) + "条,保存失败"
                                                    + (sumSize - successCount+1) + "条");
                                        }else if(sumSize==0){
                                            resultDialog.setText("下载数据总共" + 0
                                                    + "条,保存成功" + 0 + "条,保存失败"
                                                    + 0 + "条");
                                        }else{
                                            resultDialog.setText("下载数据总共" + sumSize
                                                    + "条,保存成功" + successCount + "条,保存失败"
                                                    + (sumSize - successCount) + "条");
                                        }
                                        resultDialog.showCancleLong();

                                    }
                                });

                            }
                        }.synchroDrugsdata("downloadDrugs");
                    } catch (Exception e) {
                        e.printStackTrace();
                        if (mProgressDialog != null) {
                            mProgressDialog.dismiss();
                            mProgressDialog.cancel();
                        }
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                resultDialog.setText("数据同步失败");
                                resultDialog.showCancleLong();
                            }
                        });
                    }
                }
            };
            handler.sendMessage(new Message());
        } else {
            Toast.makeText(DataSynchronizationMainActivity.this, "下载药品库数据失败", Toast.LENGTH_SHORT).show();
        }
    }

}